package com.bianyuanren.pay.controller.alipay;

import com.bianyuanren.common.core.controller.BaseController;
import com.bianyuanren.common.core.domain.AjaxResult;
import com.bianyuanren.common.utils.StringUtils;
import com.bianyuanren.pay.service.alipay.AlipayService;
import com.bianyuanren.v4.pojo.member.PpMemberSpec;
import com.bianyuanren.v4.pojo.rechargespec.PpRechargeSpec;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Administrator
 */
@RestController
@RequestMapping("/api/ali")
public class AlipayController extends BaseController {

    @Autowired
    private AlipayService alipayService;

    @PostMapping("/pay")
    public AjaxResult pay(PpRechargeSpec ppRechargeSpec, PpMemberSpec ppMemberSpec, String type) {

        if (StringUtils.isBlank(type)) {
            return AjaxResult.error("充值类型不能为空");
        }
        //充值钻石
        if ("order-recharge".equals(type)) {
            return AjaxResult.success(alipayService.alipayForRechage(ppRechargeSpec)) ;
        }
        //充值vip
        if ("order-vip".equals(type)) {
            return AjaxResult.success(alipayService.alipayForVip(ppMemberSpec)) ;
        }
        return error("error");
    }
    @PostMapping("/aliPayCallback")
    public String insertRecord(HttpServletRequest request) {
        return alipayService.aliPayCallback(request);
    }

    @PostMapping("/vipAliPayCallback")
    public String vipAliPayCallback(HttpServletRequest request) {
        return alipayService.vipAliPayCallback(request);
    }



 public static void main(String[] args) {

 String[] pswdStr = { "qwertyuiopasdfghjklzxcvbnm",
"QWERTYUIOPASDFGHJKLZXCVBNM", "0123456789",
"~!@#$%^&*()_+{}|<>?:{}" };

int pswdLen = 10;
String pswd = " ";
char[] chs = new char[pswdLen];
for (int i = 0; i < pswdStr.length; i++) {

int idx = (int) (Math.random() * pswdStr[i].length());
chs[i] = pswdStr[i].charAt(idx);

}

for (int i = pswdStr.length; i < pswdLen; i++) {

int arrIdx = (int) (Math.random() * pswdStr.length);
int strIdx = (int) (Math.random() * pswdStr[arrIdx].length());

chs[i] = pswdStr[arrIdx].charAt(strIdx);
}

for (int i = 0; i < 1000; i++) {
int idx1 = (int) (Math.random() * chs.length);
int idx2 = (int) (Math.random() * chs.length);

if (idx1 == idx2) {
continue;
}

char tempChar = chs[idx1];
chs[idx1] = chs[idx2];
chs[idx2] = tempChar;
}

pswd = new String(chs);
System.out.println(pswd);
}

    }

